home *** CD-ROM | disk | FTP | other *** search
- Q32654 Incorrect Code for Loop with Initializer i=j=constant
- C Compiler
- 5.10 | 5.10
- MS-DOS | OS/2
-
- Summary:
- The code generated for the following "for loop" is incorrect. The
- variable "i" is set up in the DI register and is loaded with the value
- 10 before the loop begins. This process causes all of the printed
- answers to be off by 10.
- Microsoft has confirmed this to be a problem in Version 5.10 of the
- C compiler. We are researching this problem and will post new
- information as it becomes available.
- The problem is related to the initialization portion of the "for
- loop;" i.e., the statement i=j=0.
- You can work around this problem by initializing one of the
- variables outside of the "for loop."
-
- More Information:
-
- int array[10]={1,2,3,4,5,6,7,8,9,10};
- main()
- {
-
-
- int i,j,k;
-
- k=0;
- /* work around by initializing i or j outside of loop: */
- /* i = 0 */
- for (i=j=0;j<10;j++)
- {
- if (array[j]==5) k=i;
-
- i++;
- }
- printf("\r\ni=%d j=%d k=%d",i,j,k);
-
- }
-
-
-
- Keywords: buglist5.10
- Updated 88/07/21 03:19
-